<template>
  <div class='goods-relevant'>
    <!-- 头部的内容 -->
    <div class="header">
      <i class="icon" />
      <span class="title">同类商品推荐</span>
    </div>
    <!-- 商品列表的轮播图 -->
    <xtx-carousel :sliders="sliders"></xtx-carousel>
  </div>
</template>

<script setup>
import { findRelGoods } from '@/api/product'
import { defineProps, ref } from 'vue'
const props = defineProps({
  goodsId: {
    type: String,
    default: ''
  }
})
// 获取同类推荐数据
const sliders = ref([])
findRelGoods(props.goodsId).then(({ result }) => {
  // 每页4条
  const size = 4
  const total = Math.ceil(result.length / size)
  for (let page = 1; page <= total; page++) {
    sliders.value.push(result.slice((page - 1) * size, page * size))
  }
  // console.log(sliders.value)
})
</script>

<style scoped lang='less'>
.goods-relevant {
  background: #fff;
  min-height: 460px;
  margin-top: 20px;

  .header {
    height: 80px;
    line-height: 80px;
    padding: 0 20px;

    .title {
      font-size: 20px;
      padding-left: 10px;
    }

    .icon {
      width: 16px;
      height: 16px;
      display: inline-block;
      border-top: 4px solid @xtxColor;
      border-right: 4px solid @xtxColor;
      box-sizing: border-box;
      position: relative;
      transform: rotate(45deg);

      &::before {
        content: "";
        width: 10px;
        height: 10px;
        position: absolute;
        left: 0;
        top: 2px;
        background: lighten(@xtxColor, 40%);
      }
    }
  }

  // 样式穿透
  :deep(.xtx-carousel) {
    height: 380px;

    .carousel {
      &-indicator {
        bottom: 30px;

        span {
          &.active {
            background: @xtxColor;
          }
        }
      }

      &-btn {
        top: 110px;
        opacity: 1;
        background: rgba(0, 0, 0, 0);
        color: #ddd;

        i {
          font-size: 30px;
        }
      }
    }
  }
}</style>